package hello;

import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 *
 * @version 0.1
 * @auth admin.
 * @time 2018/4/26 21:26
 * @since 0.1
 */
public class UserServiceImpl implements AuthenticationUserDetailsService<CasAssertionAuthenticationToken> {

    @Override
    public UserDetails loadUserDetails(CasAssertionAuthenticationToken casAssertionAuthenticationToken) throws UsernameNotFoundException {
        System.out.println(casAssertionAuthenticationToken.toString());
        //登录成功，设置用户权限
        UserDetails user =
                User.withDefaultPasswordEncoder()
                        .username(casAssertionAuthenticationToken.getName())
                        .password("password")
                        .roles("USER")
                        .build();
        return user;
    }
}
